package com.jianganming.bio.rpc.server;


import com.jianganming.bio.rpc.service.impl.HelloServiceImpl;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RpcProxyServer {
    ExecutorService executorService = Executors.newCachedThreadPool();

    public void publish(Object service){
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(8080);
            while (true){
                //监听客户端连接
                Socket socket = serverSocket.accept();
                executorService.submit(new ProcessorHandler(socket,service));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new RpcProxyServer().publish(new HelloServiceImpl());
    }

}
